/**
 * @author Steve Gao<gaofu@parllay.com>
 */
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class WallLinksStatisticsHandler extends BaseHandler {

    get pattern() {
        return '/wall/:wall_id/links';
    }

    doGET(request, response) {

        var isBusinessUser = false;
        var count = request.query.count || 5;
        var type = request.query.type || 'new'; //new or old
        var since = request.query.since || 'now';
        var platform = request.query.platform || '';
        var mode = request.query.mode || 'latest'; // latest or hot
        var source = request.query.source || null;
        var wallId = request.params.wall_id;
        var userId = request.session.user.id || (request.session.walls[request.params.wall_id] && request.session.walls[request.params.wall_id].wall_user_id) || -1;
        var status = isBusinessUser ? (request.query.status ? request.query.status : null) : (request.query.status || 'approved');

        this.Controller.getLinkStatisticsByWallId(wallId, {
            count: count, 
            type: type,
            since: since,
            status: status,
            mode: mode,
            platform: platform,
            source: source,
            userId: userId
        }, (result) => {
            response.json({
                success: true,
                data: result
            });
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = WallLinksStatisticsHandler;